package br.requisiteworks.controller;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class LabelController {

	@RequestMapping(value = "/label.do", method = RequestMethod.GET)
	public void criarLabel(@RequestParam("t") String texto,
			HttpServletResponse response) throws IOException {
		BufferedImage image = new BufferedImage(18, 140,
				BufferedImage.TYPE_INT_RGB);

		Graphics2D graphics = (Graphics2D) image.getGraphics();
		// graphics.setColor(Color.WHITE);
		graphics.fillRect(0, 0, 18, 140);

		graphics.setFont(new Font("Arial", Font.PLAIN, 13));

		graphics.rotate(-(Math.PI / 2));
		Color azul = new Color(0x22, 0x2D, 0x49);

		graphics.setColor(azul);

		graphics.drawString(texto, -135, 16);
		response.setContentType("image/gif");

		ImageIO.write(image, "gif", response.getOutputStream());
	}
}
